package com.ruoyi.web.controller.cms;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cms.domain.CmsDjType;
import com.ruoyi.cms.service.ICmsDjTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 党建栏目Controller
 * 
 * @author hct
 * @date 2022-01-22
 */
@RestController
@RequestMapping("/cms/dj/type")
public class CmsDjTypeController extends BaseController
{
    @Autowired
    private ICmsDjTypeService cmsDjTypeService;

    /**
     * 查询党建栏目列表
     */
    @PreAuthorize("@ss.hasPermi('cms:djtype:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsDjType cmsDjType)
    {
        startPage();
        List<CmsDjType> list = cmsDjTypeService.selectCmsDjTypeList(cmsDjType);
        return getDataTable(list);
    }

    /**
     * 导出党建栏目列表
     */
    @PreAuthorize("@ss.hasPermi('cms:djtype:export')")
    @Log(title = "党建栏目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsDjType cmsDjType)
    {
        List<CmsDjType> list = cmsDjTypeService.selectCmsDjTypeList(cmsDjType);
        ExcelUtil<CmsDjType> util = new ExcelUtil<CmsDjType>(CmsDjType.class);
        util.exportExcel(response, list, "党建栏目数据");
    }

    /**
     * 获取党建栏目详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:djtype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsDjTypeService.selectCmsDjTypeById(id));
    }

    /**
     * 新增党建栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:djtype:add')")
    @Log(title = "党建栏目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsDjType cmsDjType)
    {
        return toAjax(cmsDjTypeService.insertCmsDjType(cmsDjType));
    }

    /**
     * 修改党建栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:djtype:edit')")
    @Log(title = "党建栏目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsDjType cmsDjType)
    {
        return toAjax(cmsDjTypeService.updateCmsDjType(cmsDjType));
    }

    /**
     * 删除党建栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:djtype:remove')")
    @Log(title = "党建栏目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsDjTypeService.deleteCmsDjTypeByIds(ids));
    }
}
